package com.zx.sdk.util;

import static com.zx.sdk.ZxSDK.getContext;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

public class UiHelper {
    /**
     * 获取屏幕的宽度px
     *
     * @return 屏幕宽px
     */
    public static int getScreenWidth() {
        WindowManager windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics outMetrics = new DisplayMetrics();
        windowManager.getDefaultDisplay().getMetrics(outMetrics);
        return outMetrics.widthPixels;
    }

    /**
     * 获取屏幕的高度px
     *
     * @return 屏幕高px
     */
    public static int getScreenHeight() {
        WindowManager windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics outMetrics = new DisplayMetrics();
        windowManager.getDefaultDisplay().getMetrics(outMetrics);
        return outMetrics.heightPixels;
    }

    public static int dp2Px(int var0) {
        return (int)(getContext().getResources().getDisplayMetrics().density * (float)var0 + 0.5F);
    }

    public static int dp2Px(float var0) {
        return (int)(getContext().getResources().getDisplayMetrics().density * var0 + 0.5F);
    }

    public static int px2Dp(int var0) {
        return (int)((float)var0 / getContext().getResources().getDisplayMetrics().density);
    }

    public static int px2Dp(float var0) {
        return (int)(var0 / getContext().getResources().getDisplayMetrics().density);
    }

    public static float px2DpAsFloat(float var0) {
        return var0 * 1.0F / getContext().getResources().getDisplayMetrics().density;
    }
}
